# Abdusami dot dev at aliyun dot com

PROJECT_NAME = algo
# whole source code list in current project
SOURCE_CODE = main.c bitmap.c queue.c stack.c utils.c leetcode.c test.c string.c array.c sort.c search.c arch.c
OBJECT_FILES = $(addprefix obj/,$(SOURCE_CODE:.c=.o))
C_FLAGS = -Wall -Wextra -Wunused -Wformat=2 -Wnull-dereference -g
LD_FLAGS = -flto -ffunction-sections -fdata-sections

vpath %.c src

all: $(PROJECT_NAME)

# Create obj directory if it doesn't exist
obj:
	@mkdir -p obj

$(PROJECT_NAME): obj $(OBJECT_FILES)
	$(CC) $(OBJECT_FILES) $(LD_FLAGS) -o $@

# compile source codes into .o object files in obj directory
obj/%.o: %.c
	$(CC) $(C_FLAGS) -c $< -o $@

run:
	@./$(PROJECT_NAME)

clean:
	rm -rf obj *.o $(PROJECT_NAME)

debug: $(PROJECT_NAME)
	gdb -q ./$(PROJECT_NAME)